package com.pets.utils;


import lombok.Builder;
import lombok.Data;

//统一返回参数
@Data
@Builder
public class Result {

    private int code;
    private String msg;
    private Object data;

    public Result(int code, String msg, Object data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public Result() {
    }

    public static Result success(Object data) {
        return new Result(200, "操作成功", data);
    }

    public static Result success(String msg, Object data) {
        return new Result(200, msg, data);
    }
    public static Result success(String msg) {
        return new Result(200, msg, null);
    }


    public static Result error(String msg) {
        return new Result(500, msg, null);
    }

    public static Result fail(String msg) {
        Result m = new Result();
        m.setCode(-1);
        m.setData(null);
        m.setMsg(msg);
        return m;
    }

    public boolean isSuccess() {
        return code == 200; // 200 表示操作成功的状态码
    }

    public static Result fail(String mess, Object data) {
        Result m = new Result();
        m.setCode(-1);
        m.setData(data);
        m.setMsg(mess);
        return m;
    }
}
